﻿using FitnessClubManager.BLL;
using FitnessClubManager.DAL;
using FitnessClubManager.GUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QuanLyHocPhi.GUI.DuLieu
{
    public partial class FormNuocGiaiKhat : FormBase
    {
        public FormNuocGiaiKhat()
        {
            InitializeComponent();

            gridNuoc.ReadOnly = true;
            gridNuoc.AllowUserToAddRows = false;
            gridNuoc.AllowUserToDeleteRows = false;
            gridNuoc.AutoGenerateColumns = false;
            NapDanhSachNuocGK();
        }
        void NapDanhSachNuocGK()
        {
            var ls = BizNuocGiaiKhat.GetList();
            bsNuoc.DataSource = ls;
            gridNuoc.DataSource = bsNuoc;
        }

        private void btnNuoc_Them_Click(object sender, EventArgs e)
        {
            FormTaoMoiNuocGiaiKhat frm = new FormTaoMoiNuocGiaiKhat();
            frm.ShowDialog();
            NapDanhSachNuocGK();
        }

        private void btnNuoc_ChinhSua_Click(object sender, EventArgs e)
        {
            if (bsNuoc.Current != null)
            {
                FormTaoMoiNuocGiaiKhat frm = new FormTaoMoiNuocGiaiKhat(bsNuoc.Current as NuocGiaiKhat);
                frm.ShowDialog();
                NapDanhSachNuocGK();
            }
        }

        private void btnNuoc_Xoa_Click(object sender, EventArgs e)
        {
            if (bsNuoc.Current != null)
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa sản phẩm này", "Thông báo",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.OK)
                {
                    if (BizNuocGiaiKhat.Delete((bsNuoc.Current as NuocGiaiKhat).MaNuocGK))
                        NapDanhSachNuocGK();
                    else
                        DialogUtils.ShowError("Không thể xóa sản phẩm này");
                }
            }
        }
    }
}
